/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


Contants = function(){    
    
}
Contants.DeleteMessage = "Bạn có muốn xóa dòng này ?";
Contants.Fail = "Cập nhật thất bại";
Contants.Url = "http://localhost:8080/webrealtime/";
//luu tru du lieu tai may client. Giam bot tinh nang goi request len server
Contants.Save = function(obj, name) {
    localStorage.setItem(name, JSON.stringify(obj));
    console.log(name);
}
// doc lai du lieu vua duoc luu o client
Contants.read = function(name) {
    if (localStorage.getItem(name) != null) {
        var results = JSON.parse(localStorage.getItem(name));
        console.log("Contants.read ");
        console.dir(results);
        return results;
    }
    return new Array();
}

String.prototype.replaceAll = function (strTarget, strSubString) {
    var strText = this;
    var indexString = strText.indexOf(strTarget);
    while (indexString != -1) {
        strText = strText.replace(strTarget, strSubString);
        indexString = strText.indexOf(strTarget);
    }
    return strText;
}

String.prototype.trim = function () {
    var sString = this;
       if(sString == null || sString == "") {
            return "";
       }
        if (sString.length == undefined) {
            return "";
        }
        while (sString.length != 0) {
            if (sString.substring(0, 1) == ' ') {
                sString = sString.substring(1, sString.length);
            }
            else break;
        }
        while (sString.length != 0) {
            if (sString.substring(sString.length - 1, sString.length) == ' ') {
                sString = sString.substring(0, sString.length - 1);
            }
            else
                break;
        }
        return sString;
}

Array.prototype.contains = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value == this[k])
            return true;
    return false;
}

Array.prototype.searchIndex = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value == this[k])
            return k;
    return -1;
}

Array.prototype.clone = function () {
    var result = new Array();
    for (var k = 0; k < this.length; k++) {
        result.push(this[k]);
    }
    return result;
}